<?php
/**
 * Created by yujian
 * Date: 2018-09-05
 */

namespace app\admin\controller;
use think\Controller;
class Login extends Controller
{
    public function index()
    {
        $this->view->engine->layout(false);
        $tip = '';
        $username = '';
        if(request()->isPost()){
            $username = trim(input('username'));
            $password = md5(input('password'));

            $hasname = db('adminusers')->where('ad_name',$username)->find();
            if($hasname){
                $realpass = $hasname['ad_password'];
                if($realpass == $password){
                    session([
                        'prefix'         => 'module',
                        'type'           => '',
                        'auto_start'     => true,
                    ]);
                    session('username',$username);
                    session('password',$realpass);
                    session('realpass',$realpass);
                    $this->redirect('admin/index/index');
                }else{
                    $tip = '密码错误';
                }
            }else{
                $tip = '账号不存在';
            }
        }
        $this->assign('tip',$tip);
        $this->assign('username',$username);


        return view();
    }
}